package com.nativetalk.service.three.member.search;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.member.TdNtMemberClcokIn;
import com.nativetalk.bean.member.TdNtMemberDetail;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.dao.TdNtMemberDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lizhun on 16/8/12.
 */
@Service
public class ThreeMemberSearchServiceImpl implements ThreeMemberSearchService {
    private static Logger logger = Logger.getLogger(ThreeMemberSearchServiceImpl.class);
    @Resource
    private TdNtMemberDao tdNtMemberDao;

    @Override
    public RetInfo getPurchase(int memb_id) {
        String logInfo = this.getClass().getName() + ":getPurchase:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            TdNtMemberDetail tdNtMember = tdNtMemberDao.findTdNtMemberDetail(memb_id);
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取用户内购余额成功");
            retInfo.setObj(tdNtMember.getMemb_purchase_balance());
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo getPurchaseAndBalance(int memb_id) {
        String logInfo = this.getClass().getName() + ":getPurchaseAndBalance:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            TdNtMemberDetail tdNtMember = tdNtMemberDao.findTdNtMemberDetail(memb_id);
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取用户内购余额和余额成功");
            Map<String, Object> map = new HashMap<>();
            map.put("banlance",tdNtMember.getMemb_balance());
            map.put("purchaseBalance",tdNtMember.getMemb_purchase_balance());
            retInfo.setObj(map);
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public TdNtMemberClcokIn findClockInData(int memb_id) {

        return tdNtMemberDao.findMemberClockInDay(memb_id);
    }
}
